<?php

/**
 * Created by PhpStorm.
 * User: wx:wenyi2048
 * Date: 2022/3/18 0018
 * Time: 09:31
 */

namespace app\admin\controller\mk;
/*轮播图管理*/

use app\admin\Controller;
use app\common\service\BannersService;
use app\common\service\TypeService;

\think\Loader::import('controller/Controller', \think\Config::get('traits_path'), EXT);

class Banners extends Controller
{
    use \app\admin\traits\controller\Controller;
    public function index()
    {
        $param = $this->request->param();
        $service = new BannersService(); //数据处理
        $service->searchPage($this->view, $param);
        return $this->view->fetch();
    }

    public function recycleBin()
    {
        $param = $this->request->param();
        $service = new BannersService(); //数据处理
        $service->searchPage($this->view, $param, 1);
        return $this->view->fetch();
    }

    public function beforeAdd()
    {
        $typeService = new TypeService();
        $typeTree = $typeService->treeList();
        $this->view->assign('typeTree', $typeTree);
    }

    public function afterEdit()
    {
        $this->beforeAdd();
        $vo = $this->view->__get('vo');
        $tfid = $vo['types_first_id'];
        $tsid = $vo['types_second_id'];
        $ttid = $vo['types_third_id'];
        if ($tfid && $tsid && $ttid) { //有分类，组装分类名
            $types = (new TypeService())->getTypes([$tfid, $tsid, $ttid]);
            $vo['types_name'] = $types[0]['name'] . '/' . $types[1]['name'] . '/' . $types[2]['name'];
            $this->view->assign('vo', $vo);
        }
    }


    public function second()
    {
        $param = $this->request->param();
        $service = new BannersService(); //数据处理
        $service->searchPage($this->view, $param, 0, 'second');
        return $this->view->fetch();
    }

    public function secondRecycleBin()
    {
        $param = $this->request->param();
        $service = new BannersService(); //数据处理
        $service->searchPage($this->view, $param, 1, 'second');
        return $this->view->fetch();
    }
}
